#define _CRT_SECURE_NO_WARNINGS

#include<deque>
#include<vector>

namespace wzy
{
	template<class T,class Con= deque<T>>
	class stack
	{
	public:
		stack() {}
		void push(const T& x)
		{
			_con.push_back(x);
		}
		void pop()
		{
			_con.pop_back();
		}
		T& top()
		{
			return _con.back();
		}

		const T& top() const
		{
			return _con.back();
		}

		size_t size() const
		{
			return _con.size();
		}

		bool empty()const
		{
			return _con.empty();
		}
	private:
		Con _con;
	};

	template<class T,class Con = deque<T>>
	class queue
	{
	public:
		queue(){}
		void push(const T& x)
		{
			_con.push_back(x);
		}

		void pop()
		{
			_con.pop_front();
		}

		T& front()
		{
			return _con.front();
		}

		const T& front() const
		{
			return _con.front();
		}

		T& back()
		{
			return _con.back();
		}

		const T& back() const
		{
			return _con.back();
		}

		size_t size() const
		{
			return _con.size();
		}

		bool empty() const
		{
			return _con.empty();
		}
	private:
		Con _con;
	};

	template<class T>
	class Less
	{
	public:
		bool operator()(const T& x,const T& y)
		{
			return x < y;
		}
	};

	template<class T>
	class Greater
	{
	public:
		bool operator()(const T& x, const T& y)
		{
			return x > y;
		}
	};

	template<class T,class Con=vector<T>,class Compare=Less<T>>
	class priority_queue
	{
	public:
		priority_queue(){}

		void AdujstUp(int child)
		{
			int parent = (child - 1) / 2;

			Compare com;
			while (child > 0)
			{
				if (com(_con[parent],_con[child]))
				{
					swap(_con[parent], _con[child]);
					child = parent;
					parent = (child - 1) / 2;
				}
				else
					break;
			}
		}

		void push(const T& x)
		{
			_con.push_back(x);
			AdujstUp(_con.size() - 1);
		}

		void AdujstDown(int parent)
		{
			int child = parent * 2 + 1;
		
			Compare com;

			while (child < _con.size())
			{
				if (child+1 < _con.size() && com(_con[child + 1], _con[child]))
					++child;

				if (com(_con[parent],_con[child]))
				{
					swap(_con[child], _con[parent]);
					parent = child;
					child = parent * 2 + 1;
				}
				else
					break;
			}
		}

		void pop()
		{
			swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			AdujstDown(0);
		}

		const T& top()
		{
			return _con[0];
		}

		const size_t size() const
		{
			return _con.size();
		}
		
		const bool empty() const
		{
			return _con.empty();
		}
	private:
		Con _con;
	};
}